package com.xframe.domain.repository;

import com.xframe.domain.knowledgeBase.KnowledgeBase;
import com.xframe.domain.knowledgeBase.KnowledgeFiles;
import com.xframe.xdal.core.exception.DalFrameException;
import com.xframe.xdal.core.model.ConditionValue;
import com.xframe.xdal.core.model.ConditionValueCollection;
import com.xframe.xdal.core.model.DataAccessResult;
import com.xframe.xdal.core.model.IModel;
import com.xframe.xdal.core.model.mapping.ITableInfo;
import com.xframe.xdal.core.model.mapping.TableInfoBuilder;
import com.xframe.xdal.core.tran.XTransaction;
import com.xframe.xdal.core.util.IdCreateUtil;

public class KnowledgeBaseRepository extends SysBaseRepository{
    @XTransaction
    @Override
    public Integer update(IModel model, ITableInfo tableInfo) throws DalFrameException {
        System.out.println("9090909090");
        try {
            if(model instanceof KnowledgeBase){

                KnowledgeBase knowledgeBase = (KnowledgeBase)model;
                defDataBaseAccess.update(knowledgeBase);
                ConditionValueCollection conditionValueCollection = new ConditionValueCollection();
                conditionValueCollection.add(new ConditionValue("knId",knowledgeBase.getKnId()));
                defDataBaseAccess.deleteMany(TableInfoBuilder.BuildTableInfoByAnnotation(KnowledgeFiles.class),conditionValueCollection);

                Integer i = defDataBaseAccess.batchCreate(KnowledgeFiles.class,knowledgeBase.getFileList());

                return 1;
            }
            return 0;
        } catch (DalFrameException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}
